/**
 * Created by lsj on 2017/8/16.
 */
var $dg = $('#todayDg');
var dgHistory = $('#historyDg');
$(function () {
    $('#tt').tabs({
        plain: false,
        narrow: false,
        pill: false,
        justified: true
    })

    $dg.datagrid({
        //	title:'运维日志列表',
        url:contextPath+'/console/monitor/loadTodayServiceCount',
        loadMsg: '加载中...',
        width: '100%',
        height: $("#today_list").height(),
        fitColumns:true,
        pagination:false,
        singleSelect:true,
        selectOnCheck:false,
        checkOnSelect:false,
        rownumbers:true,
        emptyMsg:'暂无数据',
        toolbar: [],
        columns:[[
            {field: 'serviceId', title: '服务ID', width: 100,halign:'center',align:'left'},
            {field: 'count', title: '调用次数（次）', width: 100,halign:'center',align:'center'},
        ]],
        onLoadSuccess:function (data) {
            $("#today_total").text(data.total);
        }
    });

    dgHistory.datagrid({
        //	title:'运维日志列表',
        url:contextPath+'/console/monitor/loadHistoryServiceCount',
        loadMsg: '加载中...',
        width: '100%',
        height: $("#history_list").height(),
        fitColumns:true,
        pagination:false,
        singleSelect:true,
        selectOnCheck:false,
        checkOnSelect:false,
        rownumbers:true,
        emptyMsg:'暂无数据',
        toolbar: [],
        columns:[[
            {field: 'serviceId', title: '服务ID', width: 100,halign:'center',align:'left'},
            {field: 'count', title: '调用次数（次）', width: 100,halign:'center',align:'center'},
        ]],
        onLoadSuccess:function (data) {
            $("#his_total").text(data.total);
        }
    });


    var $today_user = $('#today_user');
    $today_user.combobox({
        method: 'get',
        url: contextPath + '/console/esbUser/getAllEsbUser',
        valueField: 'loginId',
        textField: 'note',
        editable: false,
        panelHeight:　'auto',
        prompt:　'----请选择----',
        onLoadSuccess: function (data) {
        },
        onLoadError: function () {

        },
        onShowPanel: function () {
        },
        onChange: function (loginId) {
            $dg.datagrid('reload',{loginId:loginId});
        }
    });
    var $history_user = $('#history_user');
    $history_user.combobox({
        method: 'get',
        url: contextPath + '/console/esbUser/getAllEsbUser',
        valueField: 'loginId',
        textField: 'note',
        editable: false,
        panelHeight:　'auto',
        prompt:　'----请选择----',
        onLoadSuccess: function (data) {
        },
        onLoadError: function () {

        },
        onShowPanel: function () {
        },
        onChange: function (loginId) {
            dgHistory.datagrid('reload',{loginId:loginId});
        }
    });
})

function reloadTodayCount() {
    var loginId = $('#today_user').combobox("getValue");
    $dg.datagrid('reload',{loginId:loginId});
}
function reloadHistoryCount() {
    var loginId = $('#history_user').combobox("getValue");
    dgHistory.datagrid('reload',{loginId:loginId});
}

function turnToAuthGroup(){
    var loginId = $('#history_user').combobox("getValue");
    if(loginId==""){
        apexLayer.Warn("请先选择接入用户");
        return;
    }
    self.window.location = contextPath + "/console/userAuthGroup/goAddFromCount?loginId="+loginId;
}
